package com.etc.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.entity.Customer;
import com.etc.service.CustomerService;
import com.etc.service.impl.CustomerServiceImpl;

@WebServlet("/updatePsw")
public class UpdatePswServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	
	private CustomerService CustomerService =new CustomerServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		updatePsw(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
	private void updatePsw(HttpServletRequest request, HttpServletResponse response)  throws IOException, ServletException{
		//System.out.println(1);
		String jiumima=request.getParameter("jiumima");
		String xinmima=	request.getParameter("newpowwer");
		String querenmima=	request.getParameter("querenmima");
		System.out.println(jiumima);
		System.out.println(xinmima+"----");
		System.out.println(querenmima);
		int id=1;
		Customer customer=	CustomerService.search(id);
		if(!customer.getPassword().equals(jiumima)) {
			request.setAttribute("msg", "原密码错误");
			request.getRequestDispatcher("/front/xgmm.jsp").forward(request, response);	
		}else if(!xinmima.equals(querenmima)) {
			request.setAttribute("msg", "两次新密码不一致");
			request.getRequestDispatcher("/front/xgmm.jsp").forward(request, response);	
		
		}else if("".equals(xinmima)) {
			request.setAttribute("msg", "新密码不能为空");
			request.getRequestDispatcher("/front/xgmm.jsp").forward(request, response);	
		
		}else {
			
		int i=	CustomerService.updatePassword(querenmima,id);
			request.setAttribute("msg", "修改成功");
			request.getRequestDispatcher("/front/xgmm.jsp").forward(request, response);	
		
		}


	
		}
	
}
